package com.shangxia.leetcode.greedyAlgorithm;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;

/**
 * @ProjectName: leetcode
 * @ClassName: FindContentChildren455
 * @Time: 2020/12/3
 * @Author: zhouy
 * @Description: 455. 分发饼干
 * @Experience:
 */

@Slf4j
public class FindContentChildren455 {
    public static void main(String[] args) {
        int[] g = {1, 2};
        int[] s = {1, 2, 3};
        System.out.println(findContentChildren(g, s));
    }

    /**
     * @param g 饥饿度
     * @param s 饼干
     * @return
     */
    public static int findContentChildren(int[] g, int[] s) {

        if (ObjectUtils.isEmpty(g) || ObjectUtils.isEmpty(s)) {
            return 0;
        }
        int num = 0;
        Arrays.sort(g);
        Arrays.sort(s);
        for (int i = 0; i < s.length; i++) {
            if (g[num] <= s[i]) {
                num++;
                if (num >= g.length) {
                    return num;
                }
            }
        }
        return num;
    }
}
